package com.chen.facemanager.controller;

import com.chen.facemanager.bean.Apk;
import com.chen.facemanager.service.ApkService;
import com.chen.facemanager.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(value="/apk", tags="版本管理模块")
@RestController
@RequestMapping("/apk")
public class ApkController {


    @Autowired
    private ApkService apkService;

    @ApiOperation(value = "发布新版本",notes = "发布新版本")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "version", value = "version", required = true, dataType = "String"),
            @ApiImplicitParam(name = "url", value = "下载地址", required = true, dataType = "String")
    })
    @PostMapping("/saveAPk")
    public Result saveAPk(String version, String url){

        if (apkService.save(version,url)){
            return new Result(200,"ok","成功");
        } else {
            return new Result(400,"error","失败");
        }
    }


    @ApiOperation(value = "获取新版本",notes = "获取新版本")
    @PostMapping("/getAPk")
    public Result getAPk(){
        Apk apk = apkService.getMaxVersionApk();
        if (apk != null){
            return new Result(200,"ok",apk);
        } else {
            return new Result(400,"error",null);
        }
    }

}
